package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.user.model.User;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "csf_inbound")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfInbound extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_10, index = true, unique = true)
    private String code;

    @One(value = "outbound", target = CsfOutbound.class, groups = {"CsfInbound.search","CsfInbound.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long outboundId;

    @One(value = "ladingBill", target = CsfLadingBill.class, fieldset = {"id", "billCode"},groups = {"CsfInbound.search","CsfInbound.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long billId;

    @One(value = "loan", target = CsfLoan.class, fieldset = {"id", "code"}, groups = {"CsfInbound.search","CsfInbound.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long loanId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long contractId;

    @One(value = "shipperCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long shipper;

    @One(value = "consigneeCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long consignee;

    @DataField(value = IConstants.CSF_INBOUND_DATA_TYPE.INBOUND_STATE, required = true, index = true)
    private String state = States.DISPATCHED;

    private Date inDate;

    @One(value = "confirmingPerson", target = User.class, fieldset = {"id", "name"}, groups = {"CsfInbound.search","CsfInbound.detail"})
    private Long confirmedBy;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getOutboundId() {
        return outboundId;
    }

    public void setOutboundId(Long outboundId) {
        this.outboundId = outboundId;
    }

    public Long getBillId() {
        return billId;
    }

    public void setBillId(Long billId) {
        this.billId = billId;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getShipper() {
        return shipper;
    }

    public void setShipper(Long shipper) {
        this.shipper = shipper;
    }

    public Long getConsignee() {
        return consignee;
    }

    public void setConsignee(Long consignee) {
        this.consignee = consignee;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getInDate() {
        return inDate;
    }

    public void setInDate(Date inDate) {
        this.inDate = inDate;
    }

    public Long getConfirmedBy() {
        return confirmedBy;
    }

    public void setConfirmedBy(Long confirmedBy) {
        this.confirmedBy = confirmedBy;
    }

    public interface States {
        String DISPATCHED = "DISPATCHED"; //待收货
        String PENDING = "PENDING"; //待入库
        String COMPLETED = "COMPLETED"; //已入库
    }
}
